<?php
/**
 * Created by PhpStorm.
 * User: W
 * Date: 2018/12/25
 * Time: 11:46
 */

namespace app\sports_admin\controller;
use app\exception\QuestionException;
use app\sports_admin\service\Question as QuestionService;
use app\sports_admin\model\Help;
use think\Request;

class Question extends Base
{
    //法律援助问题
    public function index()
    {
        return view("index");
    }
    //法律援助问题列表
    public function answerList()
    {
        $params = Request::instance()->only(['page','rows','sort','sortOrder','searchName']);
        $page = intval($params['page']) ? intval($params['page']) : 1;
        $rows = intval($params['rows']) ? intval($params['rows']) : 15;
        $sort = trim($params['sort']) ? trim($params['sort']) : 'school_id';
        $sortOrder = trim($params['sortOrder']) ? trim($params['sortOrder']) : 'asc';
        $searchName = trim($params['searchName']);
        return Help::answerList($page,$rows,$sort,$sortOrder,$searchName);
    }
    //编辑法律援助问题页面
    public function upPage()
    {
        $id = Request::instance()->only('id');
        $data = Help::detail($id['id']);

        return view('help',compact("data"));
    }
    //回复法律援助问题
    public function updateQuestion(Request $request)
    {
        if($request->isAjax()){
            $data = Help::updateQuestion();
            if(!$data){
                throw new QuestionException([
                    'msg'=>'更改失败',
                    'errorCode'=>400
                ]);
            }
            return json(['code'=>200,'msg'=>'更改成功']);
        }
    }
    //添加援助问题页面
    public function addPage()
    {
        return view('add');
    }
    //添加援助问题
    public function addQuestion(Request $request)
    {
        if($request->isAjax()){
            $data = Help::addQuestion();
            if(!$data){
                throw new QuestionException([
                    'msg'=>'添加失败',
                    'errorCode'=>400
                ]);
            }
            return json(['code'=>200,'msg'=>'添加成功']);
        }
    }
}